home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-02 | 7.7 KB | 283 lines | [TEXT/KAHL] |
- /******************************************************************************
- CMovie.c
-
- The Movie Class
-
- Displays a standard QuickTime Movie.
-
- This is a read-only class that allows you to specify and play a QuickTime
- movie with minimal other features. It is designed to simply allow the
- importation and display of movie files. The movies are controlled by
- the standard movie controller.
-
- This class could be expanded to allow editing and more…
-
- SUPERCLASS = CPane
-
- Copyright © 1992 Joe Zobkiw. All rights reserved.
- Portions Copyright © 1990 Symantec Corporation. All rights reserved.
-
- Copyright © 1995 Gregory Bonk. All rights reserved.
- Changes upgrade to TPM 7.0.7
- ******************************************************************************/
-
- #include "CMovie.h"
- #include "CEBCollaborator.h"
- #include "Defines.h"
- #include <Commands.h>
- #include <Global.h>
- #include <CPaneBorder.h>
- #include <TCLUtilities.h>
- #include <TBUtilities.h>
-
- extern CEBCollaborator *gEBCollaborator;
-
- TCL_DEFINE_CLASS_D1(CMovie, CPane);
-
- /******************************************************************************
- CMovie
-
- ******************************************************************************/
- CMovie::CMovie()
- {
- // initialize our instance variables
-
- itsMovie = NULL;
- itsMovieRefNum = 0;
- itsController = NULL;
-
- TCL_END_CONSTRUCTOR
- }
-
-
- /******************************************************************************
- ~CMovie
-
- ******************************************************************************/
- CMovie::~CMovie()
- {
- TCL_START_DESTRUCTOR
-
- ForgetInstanceVariables();
- CancelDependency(gEBCollaborator);
- }
-
-
- /******************************************************************************
- ForgetInstanceVariables
-
- clears the instance variables of this class
- ******************************************************************************/
- void CMovie::ForgetInstanceVariables(void)
- {
- if (itsMovie)
- {
- DisposeMovie(itsMovie);
- itsMovie = NULL;
- }
- if (itsMovieRefNum)
- {
- CloseMovieFile(itsMovieRefNum);
- itsMovieRefNum = 0;
- }
- if (itsController)
- {
- DisposeMovieController(itsController);
- itsController = NULL;
- }
- }
-
- /******************************************************************************
- IMovie
-
- Initialize a Movie object
- ******************************************************************************/
- void CMovie::IMovie( CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight,
- short aHEncl, short aVEncl,
- SizingOption aHSizing, SizingOption aVSizing, FSSpec *aMovieSpec)
- {
-
- CPane::IPane(anEnclosure, aSupervisor,
- aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
-
-
- SetWantsClicks(true); // we want to receive clicks
-
-
- // we want a simple border in case we decide to resize the frame to be
- // smaller than it’s enclosure. this will make it look nicer.
-
- itsBorder = new(CPaneBorder);
- itsBorder->IPaneBorder(kBorderFrame);
-
- // SetCanBeGopher(true); // we want be a gopher!
- // BecomeGopher(true);
-
- // we want to recieve events from gEBCollaborator which is our provider…
- // the one whom we depend upon
-
- DependUpon(gEBCollaborator);
-
- // if we have a movie to open (the user selected Open… instead of New) then
- // open the movie!
-
- if (aMovieSpec)
- ImportMovie(aMovieSpec);
- }
-
-
- /******************************************************************************
- ProviderChanged
-
- Our Provider has changed
- ******************************************************************************/
- void CMovie::ProviderChanged( CCollaborator *aProvider, long reason, void* info)
- {
- short eventHandled;
-
- switch(reason)
- {
- // kEventRecordReason is the only reason we deal with these days
- case kEventRecordReason:
-
- // we might end up drawing because of this MCPlayer event
- // so we must be sure our port is set up correctly.
-
- Prepare();
-
- // see if the movie controller would like the event or not
-
- eventHandled = MCIsPlayerEvent(itsController, (EventRecord*)info);
- if (eventHandled == TRUE)
- ((EventRecord*)info)->what = nullEvent;
-
- // we handled the event so we change it to a null event
- // so it is (in effect) ignored elsewhere.
-
- break;
- default:
- break;
- }
-
- inherited::ProviderChanged(aProvider, reason, info);
- }
-
- /******************************************************************************
- DoClick (OVERRIDE)
-
- This will get called if we click outside of the movie but still
- within the Movie Pane (which is currently sticky to the size of the window)
- ******************************************************************************/
- void CMovie::DoClick(Point hitPt, short modifierKeys, long when)
- {
- // this alert will beep the first two times and show itself the third time
- // and thereafter. It will simply remind the user that clicking in the empty
- // area of the CMovie Pane is fruitless other than showing this annoying alert.
-
- if (active)
- NoteAlert(kMovieDoClickALRT, nil);
- }
-
- /******************************************************************************
- ImportMovie
-
- Use the movie pointed to by spec as our movie. This routine imports
- the given movie, replacing any previous movies that were used in this pane.
-
- ******************************************************************************/
- void CMovie::ImportMovie(FSSpec *aSpec)
- {
- Rect movieRect;
- Boolean locked;
-
- if (aSpec == NULL) // hop out if there is no spec to import
- return;
-
- Prepare(); // prepare for drawing, etc.
-
- ForgetInstanceVariables(); // forget our current movie & controller
-
- // open the movie file and create a new movie from the file
-
- FailOSErr(OpenMovieFile(aSpec, &itsMovieRefNum, fsRdPerm));
- FailOSErr(NewMovieFromFile(&itsMovie, itsMovieRefNum, NULL, NULL, newMovieActive, NULL));
-
- // get the bounds for the movie and make sure the top left is 0,0
- // so the movie won't be offset within the window
-
- GetMovieBox(itsMovie, &movieRect);
- FailOSErr(GetMoviesError());
- OffsetRect(&movieRect,-movieRect.left,-movieRect.top);
- SetMovieBox(itsMovie, &movieRect);
- FailOSErr(GetMoviesError());
-
- // rewind the movie
-
- GoToBeginningOfMovie(itsMovie);
- FailOSErr(GetMoviesError());
-
- // create our controller
-
- itsController = NewMovieController(itsMovie, &movieRect, mcWithFrame+mcTopLeftMovie);
- FailOSErr(GetMoviesError());
-
- Refresh(); // redraw ourselves
- }
-
-
- /******************************************************************************
- Dawdle {OVERRIDE}
-
- Call MoviesTask here if we have a movie and it is playing. MoviesTask()
- handles updating the movie for us. It will update the movie in the background
- also.
-
- ******************************************************************************/
- void CMovie::Dawdle(long *maxSleep)
- {
- if (itsMovie)
- {
- if (!IsMovieDone(itsMovie))
- {
- Prepare(); // get ready to draw
- MoviesTask(itsMovie, 0); // update the movie
- FailOSErr(GetMoviesError()); // check the error condition
- }
- }
- }
-
-
- /******************************************************************************
- Draw {OVERRIDE}
-
- Draw a Movie and the controller if need be.
-
- ******************************************************************************/
- void CMovie::Draw(Rect *area)
- {
- Rect tempRect;
-
-
- Prepare(); // prepare to draw
-
- // draw our movie or fill the pane with gray pattern if we have no movie
-
- if (itsMovie)
- {
- UpdateMovie(itsMovie); // update the movie next time MoviesTask is called
- FailOSErr(GetMoviesError()); // check for errors
- MoviesTask(itsMovie, 0); // actually perform the update
- FailOSErr(GetMoviesError()); // check for errors
- } else
- {
- LongToQDRect( &aperture, &tempRect);
- FillRect(&tempRect, &gray);
- }
-
-
- if (itsController) // if we have a controller, draw it here
- MCDraw(itsController, GetMacPort());
- }
-
-